package core.games;

import core.score.BowlingScoreInAustralia;
import core.score.BowlingScoreInChina;
import domain.enums.GameType;

import java.util.HashMap;
import java.util.Map;

import static domain.enums.GameType.BASKETBALL;
import static domain.enums.GameType.TENNIS;


public class GameFactory {
    private final static Map<GameType, Game> GAME_MAP = new HashMap<>(8);

    // 简单工厂模式
    public static Game createGame(GameType type) {
        if (GAME_MAP.containsKey(type)) {
            // 克隆一个game实例。原型模式
            return GAME_MAP.get(type).clone();
        }
        Game game = null;
        // 策略模式
        switch (type) {
            case BOWLING_CHINA:
                game = new BowlingGame(new BowlingScoreInChina());
                GAME_MAP.put(GameType.BOWLING_CHINA, game);
                break;
            case BOWLING_AUSTRALIA:
                game = new BowlingGame(new BowlingScoreInAustralia());
                GAME_MAP.put(GameType.BOWLING_AUSTRALIA, game);
                break;
            case BASKETBALL:
                // todo something
                System.out.println(BASKETBALL);
                break;
            case TENNIS:
                // todo something
                System.out.println(TENNIS);
                break;
        }
        return game;
    }
}
